import vue from '@vitejs/plugin-vue';
import { defineConfig } from 'vite'
import { resolve } from 'path';
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from 'unplugin-vue-components/resolvers';
import pxtoviewport from 'postcss-px-to-viewport';
import legacy from '@vitejs/plugin-legacy';
// https://vitejs.dev/config/
export default defineConfig({
  // publicPath: process.env.NODE_ENV === 'production' ? '/vant-demo/' : '/',
  css: {
    preprocessorOptions: {
      postcss: {
        plugins: [
          // autoprefixer(),
          pxtoviewport({
            unitToConvert: 'px',
            viewportWidth: 375,
            viewportHeight: 812,
            unitPrecision: 3,
            viewportUnit: "vw",
            minPixelValue: 1,
            mediaQuery: false
          })
        ]
      }
    }
  },
  build: {
    target: 'es2015',
  },
  plugins: [
    vue(),
    Components({
      resolvers: [VantResolver()],
    }),
    legacy({
      targets: ['Chrome 69'],
      additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
      modernPolyfills: true,
    }),
  ],
  resolve: {                                       // +++
    alias: {
      '@': resolve(__dirname, './src')         // +++
    }                                            // +++
  },
  server: {
    port: 8029,
    host: true,
    open: false,//是否自动打开
  },
})
